import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/hj_page/main_page/provider/module_provider.dart';
import 'package:tiktokadult/hj_page/short_video/short_video_logic.dart';
import 'package:tiktokadult/hj_page/short_video/view/short_video_menu.dart';

import '../../hj_model/video_model.dart';

class ShortVideoMainLogic extends GetxController with GetSingleTickerProviderStateMixin {
  RxInt tabIndexState = 3.obs; // 默认热门
  RxBool isMenuShowState = true.obs;
  Rx<VideoModel?> currentUserModel = Rx<VideoModel?>(null);
  TabController? tabController;

  List<String> get typesMenu => [ "关注", "直播", "推荐","发现",];

  ShortVideoMainLogic({required int index}) : super() {
    tabIndexState.value = index;
  }

  @override
  void onInit() {
    super.onInit();
    ShortVideoMenu.addListen(_menuListen);
    isMenuShowState.value = ShortVideoMenu.isShow;
    tabController = TabController(length: typesMenu.length, vsync: this, initialIndex: tabIndexState.value);
    tabController?.addListener(_tabIndexLister);
  }

  void _menuListen(bool isShow) {
    isMenuShowState.value = isShow;
  }

  void _tabIndexLister() {
    if (ShortVideoLogic.tabMIndex != tabController?.index) {
      ShortVideoLogic.tabMIndex = tabController?.index ?? 0;
      tabIndexState.value = tabController?.index ?? 0;
      ShortVideoLogic.play();
    }
  }

  void jumpToLive() {
    tabController?.index = 0;
  }

  @override
  void dispose() {
    ShortVideoMenu.removeLister(_menuListen);
    super.dispose();
  }
}
